import request from '@/utils/request'
// import qs from 'qs'

// 用户管理

// 删除用户
export function delUser (params) {
  var data = fromData(params)
  return request({
    url: '/user/del_user',
    method: 'post',
    data
  })
}

// 删除用户组
export function delGroup (params) {
  var data = fromData(params)
  return request({
    url: '/user/del_group',
    method: 'post',
    data
  })
}

// 增加用户
export function addUser (params) {
  var data = fromData(params)
  return request({
    url: '/user/addUser',
    method: 'post',
    data
  })
}

// 增加用户组
export function addGroup (params) {
  var data = fromData(params)
  return request({
    url: '/user/addGroup',
    method: 'post',
    data
  })
}

// 显示所有用户组
export function getUserArray (params) {
  var data = fromData(params)
  return request({
    url: '/user/getUserArray',
    method: 'post',
    data
  })
}

// 查看用户组下所有用户信息
export function getGroupUserInfo (params) {
  var data = fromData(params)
  return request({
    url: '/user/getGroupUserInfo',
    method: 'post',
    data
  })
}

// 查看用户信息
export function getUserInfo (params) {
  var data = fromData(params)
  return request({
    url: '/user/getUserInfo',
    method: 'post',
    data
  })
}

// 查看用户组信息
export function getGroupInfo (params) {
  var data = fromData(params)
  return request({
    url: '/user/getGroupInfo',
    method: 'post',
    data
  })
}

// 编辑用户
export function editUser (params) {
  var data = fromData(params)
  return request({
    url: '/user/editUser',
    method: 'post',
    data
  })
}

// 编辑用户组
export function editGroup (params) {
  var data = fromData(params)
  return request({
    url: '/user/editGroup',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
